<template>
  <div>
    <div class="myRelease">
      <table border="1" width='100%' cellspacing="0" cellpadding="0" id="myRelesa"
             style="font-size:18px;text-align: center;">
        <tr height="40">
          <th width="445">标题</th>
          <th width="200">发布时间</th>
          <th width="230">操作</th>
        </tr>
        <!--<tr height="40" style="font-size:13px;">-->
          <!--<td>1</td>-->
          <!--<td>1</td>-->
          <!--<td>-->
            <!--<el-button class="checkView" :name=1 type="button" @click="dialogVisibles($event)">查看</el-button>-->
            <!--&lt;!&ndash;<el-button type="button" class="deleteList" @click="open6($event,item.id)">删除</el-button>&ndash;&gt;-->
            <!--<el-button type="button" class="deleteList" @click="open996($event,1)">编辑</el-button>-->

          <!--</td>-->
        <!--</tr>-->
        <tr height="40" style="font-size:13px;" :id=item.id  v-for="item in  items">
          <td>{{item.projectName}}</td>
          <td>{{format(item.startTime,'yyyy-MM-dd HH:mm:ss')}}</td>
          <td>
            <el-button class="checkView" :name=item.id type="button" @click="dialogVisibles($event)">查看</el-button>
            <el-button type="button" class="deleteList" @click="open996($event,item.id)">编辑</el-button>
            <el-button type="button"  class="deleteList" @click="open6($event,item.id)">删除</el-button>
          </td>
        </tr>
      </table>
      <el-dialog title="更改项目截止日期" :visible.sync="dialogFormVisiblem">
        <el-form :model="form">
          <el-form-item label="截止日期" :label-width="formLabelWidth">
            <!--<el-input v-model="form.name" auto-complete="off"></el-input>-->
            <div class="block">
              <el-date-picker
                v-model="form.name"
                type="datetime"
                placeholder="选择日期时间"
                align="right"
                :picker-options="pickerOptions1">
              </el-date-picker>
            </div>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisiblem = false">取 消</el-button>
          <el-button type="primary" @click="btnout()">确 定</el-button>
        </div>
      </el-dialog>

      <el-dialog
        title="项目信息"
        :visible.sync="dialogVisible"
        size="tiny"
        :before-close="handleClose" id="classbb">
        <Fabuinformation :message1=parentMsg v-if=dialogVisible ></Fabuinformation>
      </el-dialog>
      <div class="pages_a">
        <div class="block">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="currentPage3"
            :page-size="12"
            layout="prev, pager, next, jumper"
            :total="counts">
          </el-pagination>
        </div>

      </div>

    </div>
  </div>
</template>

<script>
  import Fabuinformation from '@/components/Fabuinformation'
  export default {
    data () {
      return {
        currentPage3: 1,
        counts:10,
        dialogVisible: false,
        items:[],
        parentMsg:'',
        userId:'',
        dialogFormVisiblem: false,
        form: {
          name: '',
          region: '',
          date1: '',
          date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: ''
        },
        formLabelWidth: '120px',
        pickerOptions1: {
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date());
            }
          }, {
            text: '昨天',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit('pick', date);
            }
          }, {
            text: '一周前',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', date);
            }
          }]
        }
      }
    },
    methods: {
      btnout(){
        let that=this
        let usedid=sessionStorage.getItem('bieer')
        let enttime=that.format(that.form.name,'yyyy-MM-dd HH:mm:ss')
        $.ajax({
          type: "post",
          url: local+"/awm/userManage/updateEndtime",
          data: {
            id:usedid,
            endTime:enttime
          },
          dataType: "json",

          success: function(data){
            console.log(data)
            that.$message.error(data.responseText);
            that.dialogFormVisiblem = false

          },
          error:function(aa){
            console.log(aa)
          }
        });

      },
      open996($event,id){
        sessionStorage.setItem('bieer',id)
       this.dialogFormVisiblem = true
      },
      setCookie: function (cname, cvalue, exdays) {
        var d = new Date();
        d.setTime(d.getTime() + (exdays * 60 * 1000));
        var expires = "expires=" + d.toUTCString();
        console.info(cname + "=" + cvalue + "; " + expires);
        document.cookie = cname + "=" + cvalue + "; " + expires;
        console.info(document.cookie);
      },
      //获取cookie
      getCookie: function (cname) {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
          var c = ca[i];
          while (c.charAt(0) == ' ') c = c.substring(1);
          if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
        }
        return "";
      },
      //清除cookie
      clearCookie: function () {
        this.setCookie("username", "", -1);

      },
      handleClose(done) {
            done();

      },
      dialogVisibles(e){
        this.dialogVisible = true
        this.parentMsg=$(e.currentTarget).attr('name')
      },
      open6 (e,tid) {

        this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          var that=this
          console.log(tid)
          $.ajax({
            type: "post",
            url: local+"/awm/userManage/deleteByneed",
            data: {

              tenderId :tid
            },
            dataType: "json",

            success: function(data){
                console.log(data)
                if(data.resultData==1){
                  $("#" +tid+ "").remove()
                    that.$message({
                       type: 'success',
                       message: '删除成功!'
                    })

                }else if(data.resultData==2){
                  that.$message({
                    type: 'success',
                    message: '删除失败!'
                  })
                }else if(data.resultData==3){
                  that.$message({
                    type: 'success',
                    message: '已投标项目不可删除!'
                  })
                }

            },
            error:function(aa){
              console.log(aa)
            }
          });

        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      },

      handleSizeChange (val) {
        console.log(`每页 ${val} 条`)
        this.myfabu(10,val)
        window.scrollTo(0,0);
      },
      handleCurrentChange (val) {
        console.log(`当前页: ${val}`)
        this.myfabu(10,val)
        window.scrollTo(0,0);
      },
      myfabu(countt,pagee){
         let that=this
        $.ajax({
          type: "post",
          url: local+"/awm/userManage/selectListTender",
          data: {

            count:countt,
            page:pagee
          },
          dataType: "json",
          beforeSend:function (xhr) {
            xhr. withCredentials=true
          },
          success: function(data){
              if(data.code==202){
                  that.$message.error('登录过期请重新登录');
                sessionStorage.clear()
                //清除cookie
                that.setCookie("login", "", -1);
                  let t;
                  clearTimeout(t)
                  t = setTimeout(function (){
                   that.$router.push({path: '/Entry',query: {redirect:'/Myaddress'}})
                  }, 3000);
                }else{
                  that.counts=data.resultData.count
                  that.items=data.resultData.list
                }

          },
          error:function(aa){
            console.log(aa)
          }
        });
      },
      format(time, format) {
        var t = new Date(time);
        var tf = function(i){return (i < 10 ? '0' : '') + i};
        return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a){
          switch(a){
            case 'yyyy':
              return tf(t.getFullYear());
              break;
            case 'MM':
              return tf(t.getMonth() + 1);
              break;
            case 'mm':
              return tf(t.getMinutes());
              break;
            case 'dd':
              return tf(t.getDate());
              break;
            case 'HH':
              return tf(t.getHours());
              break;
            case 'ss':
              return tf(t.getSeconds());
              break;
          }
        })
      },
    },

    mounted () {

      this.userId = sessionStorage.getItem('userId')
      this.myfabu(10,1)
    },
    components: {
      Fabuinformation
    }
  }
</script>

<style scoped>
  .myRelease {
    width: 100%;
    height: 498px;
    /*background: pink;*/
    position: relative;
  }

  .checkView {
    width: 58px;
    height: 20px;
    border: 1px solid #9d9d9d;
    font-size: 12px;
    border-radius: 5px;
    /*margin-right: 30px;*/
    padding:0;
    background: buttonface;
  }

  .deleteList {
    width: 58px;
    height: 20px;
    border: 1px solid #9d9d9d;
    font-size: 12px;
    border-radius: 5px;
    line-height: 20px;
    padding: 0;
    background: buttonface;
  }

  .pages_a {
    width: 100%;
    height: 30px;
    position: absolute;
    bottom: -40px;
    left: 500px;
  }
  .el-message-box__wrapper .el-button--primary,.el-message-box__wrapper .el-button--primary:hover {
    color: #fff;
    background-color:#ff8328;
    border-color: #ff8328;
  }
  .el-dialog--small {
    width: 40%;
  }
  .el-dialog .el-button--primary{
    color: #fff;
    background-color:#ff8328;
    border-color: #ff8328;
  }
  .block{
    width:100px;
  }
.el-date-editor.el-input {
width: 193px;
margin-left: 20px;
}
</style>
